package com.example.shoppingdemo.nslcommodity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.myview.RoundRectImageView;

import java.util.List;

public class CheckoutAdapter extends RecyclerView.Adapter<CheckoutAdapter.CheckoutHolder>{
    private Context mcontext;
    private List<CheckoutModel>modelList;

    public CheckoutAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setModelList(List<CheckoutModel> modelList) {
        this.modelList = modelList;
    }

    @NonNull
    @Override
    public CheckoutHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        CheckoutHolder holder=new CheckoutHolder(LayoutInflater.from(mcontext).inflate(R.layout.checkout_item,parent,false));
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull CheckoutAdapter.CheckoutHolder holder, int position) {
        holder.icon.setImageResource(modelList.get(position).getIcon());
        holder.title.setText(modelList.get(position).getTitle());
        holder.sku.setText(modelList.get(position).getSku());
        holder.money.setText(modelList.get(position).getMoney());
        holder.numder.setText(modelList.get(position).getNumder());
    }

    @Override
    public int getItemCount() {
        return null==modelList?0:modelList.size();
    }

    class CheckoutHolder extends RecyclerView.ViewHolder{
        RoundRectImageView icon;
        TextView title;
        TextView sku;
        TextView money;
        TextView numder;
        public CheckoutHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.image_checkout_tupian);
            title=itemView.findViewById(R.id.text_checkout_title);
            sku=itemView.findViewById(R.id.text_checkout_sku);
            money=itemView.findViewById(R.id.text_checkout_money);
            numder=itemView.findViewById(R.id.text_checkout_numder);
        }
    }
}
